<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="玖忆;文鹤;博客">
    
    <meta name="author" content="meteor">
    <!-- preconnect -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    
    
    <!--- Seo Part-->
    
    <link rel="canonical" href="https://wait-you.github.io/2023/06/06/git常用命令/"/>
    <meta name="robots" content="index,follow">
    <meta name="googlebot" content="index,follow">
    <meta name="revisit-after" content="1 days">
    
        <meta name="description" content="# Git 常用命令 # 查看版本号  git --version  # 清屏  clear  # 设置签名  git config --global user.name  “dujinliang”  # 设置邮箱  git config --global user.email “1162378922@qq.com ”  # 查看设置  git config --global --list  #">
<meta property="og:type" content="article">
<meta property="og:title" content="Git常用命令">
<meta property="og:url" content="https://wait-you.github.io/2023/06/06/Git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/index.html">
<meta property="og:site_name" content="玖忆">
<meta property="og:description" content="# Git 常用命令 # 查看版本号  git --version  # 清屏  clear  # 设置签名  git config --global user.name  “dujinliang”  # 设置邮箱  git config --global user.email “1162378922@qq.com ”  # 查看设置  git config --global --list  #">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154218643.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154444325.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154509695.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154531941.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154603510.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154648468.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154708513.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407154739663.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407160838761.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407160902432.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407160924479.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407160942142.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2021040716101181.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BlbmFudXQ=,size_16,color_FFFFFF,t_70#pic_center">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407161030420.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407161051391.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/20210407161122503.png">
<meta property="article:published_time" content="2023-06-06T00:41:10.000Z">
<meta property="article:modified_time" content="2023-06-05T08:41:27.523Z">
<meta property="article:author" content="meteor">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://tuchuang.wenhe9.cn/20210407154218643.png">
    
    
    <!--- Icon Part-->
    <link rel="icon" type="image/png" href="/images/wenhe.png" sizes="192x192">
    <link rel="apple-touch-icon" sizes="180x180" href="/images/wenhe.png">
    <meta name="theme-color" content="#f1404b">
    <link rel="shortcut icon" href="/images/wenhe.png">
    <!--- Page Info-->
    
    <title>
        
            Git常用命令 -
        
        玖忆
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    
<link rel="stylesheet" href="/assets/fonts.css">

    <!--- Font Part-->
    
    
    
    

    <!--- Inject Part-->
    
    <script id="hexo-configurations">
    let Global = window.Global || {};
    Global.hexo_config = {"hostname":"wait-you.github.io","root":"/","language":"zh-CN"};
    Global.theme_config = {"articles":{"style":{"font_size":"16px","line_height":1.5,"image_border_radius":"14px","image_alignment":"center","image_caption":false,"link_icon":true},"word_count":{"enable":true,"count":true,"min2read":true},"author_label":{"enable":true,"auto":false,"list":[]},"code_block":{"copy":true,"style":"mac","font":{"enable":false,"family":null,"url":null}},"toc":{"enable":true,"max_depth":3,"number":false,"expand":true,"init_open":true},"copyright":true,"lazyload":true,"recommendation":{"enable":false,"title":"推荐阅读","limit":3,"placeholder":"http://tuchuang.wenhe9.cn/default-bg.jpg","skip_dirs":[]}},"colors":{"primary":"#f1404b","secondary":null},"global":{"fonts":{"chinese":{"enable":false,"family":null,"url":null},"english":{"enable":false,"family":null,"url":null}},"content_max_width":"1000px","sidebar_width":"210px","hover":{"shadow":true,"scale":false},"scroll_progress":{"bar":true,"percentage":true},"busuanzi_counter":{"enable":true,"site_pv":true,"site_uv":true,"post_pv":true},"pjax":true,"open_graph":true,"google_analytics":{"enable":false,"id":null}},"home_banner":{"enable":true,"style":"static","image":{"light":"http://tuchuang.wenhe9.cn/default-bg.jpg","dark":"http://tuchuang.wenhe9.cn/default-bg.jpg"},"title":"玖忆","subtitle":{"text":["我本微末凡尘、可也心向天空"],"hitokoto":{"enable":false,"api":"https://v1.hitokoto.cn"},"typing_speed":100,"backing_speed":80,"starting_delay":500,"backing_delay":1500,"loop":true,"smart_backspace":true},"text_color":{"light":"#fff","dark":"#d1d1b6"},"text_style":{"title_size":"2.8rem","subtitle_size":"1.5rem","line_height":1.2},"custom_font":{"enable":false,"family":null,"url":null},"social_links":{"enable":true,"links":{"github":"https://gitee.com/du-jinliang","instagram":null,"zhihu":null,"twitter":null,"email":"dujinliang9@163.com"}}},"plugins":{"feed":{"enable":false},"aplayer":{"enable":false,"type":"fixed","audios":[{"name":null,"artist":null,"url":null,"cover":null}]},"mermaid":{"enable":false,"version":"9.3.0"}},"version":"2.1.4","navbar":{"auto_hide":true,"color":{"left":"#f78736","right":"#367df7","transparency":35},"links":{"Home":{"path":"/","icon":"fa-regular fa-house"}},"search":{"enable":false,"preload":true}},"page_templates":{"friends_column":2,"tags_style":"blur"},"home":{"sidebar":{"enable":true,"position":"left","first_item":"menu","announcement":null,"links":null},"article_date_format":"auto","categories":{"enable":true,"limit":3},"tags":{"enable":true,"limit":3}}};
    Global.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 个月前","year":"%s 年前"};
    Global.data_config = {"masonry":false};
  </script>
    
    <!--- Fontawesome Part-->
    
<link rel="stylesheet" href="/fontawesome/fontawesome.min.css">

    
<link rel="stylesheet" href="/fontawesome/brands.min.css">

    
<link rel="stylesheet" href="/fontawesome/solid.min.css">

    
<link rel="stylesheet" href="/fontawesome/regular.min.css">

    
    
    
    
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fa-solid fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="main-content-container">

        <div class="main-content-header">
            <header class="navbar-container">
    
    <div class="navbar-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                
                玖忆
                
            </a>
        </div>

        <div class="right">
            <!-- PC -->
            <div class="desktop">
                <ul class="navbar-list">
                    
                        
                            <li class="navbar-item">
                                <!-- Menu -->
                                <a class="" 
                                    href="/"  >
                                    
                                        
                                            <i class="fa-regular fa-house"></i>
                                        
                                        首页
                                    
                                </a>
                                <!-- Submenu -->
                                
                            </li>
                    
                    
                </ul>
            </div>
            <!-- Mobile -->
            <div class="mobile">
                
                <div class="icon-item navbar-bar">
                    <div class="navbar-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mobile drawer -->
    <div class="navbar-drawer">
        <ul class="drawer-navbar-list">
            
                
                    <li class="drawer-navbar-item flex-center">
                        <a class="" 
                        href="/"  >
                             
                                
                                    <i class="fa-regular fa-house"></i>
                                
                                首页
                            
                        </a>
                    </li>
                    <!-- Submenu -->
                    
            

        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="main-content-body">

            

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="post-page-container">
        <div class="article-content-container">

            
            
                <div class="article-title">
                    <h1 class="article-title-regular">Git常用命令</h1>
                </div>
            
                
            

            
                <div class="article-header">
                    <div class="avatar">
                        <img src="/images/wenhe.png">
                    </div>
                    <div class="info">
                        <div class="author">
                            <span class="name">meteor</span>
                            
                                <span class="author-label">Lv3</span>
                            
                        </div>
                        <div class="meta-info">
                            <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fa-regular fa-pen-fancy"></i>&nbsp;
        <span class="desktop">2023-06-05 16:41:10</span>
        <span class="mobile">2023-06-05 16:41</span>
        <span class="hover-info">创建</span>
    </span>
    
        <span class="article-date article-meta-item">
            <i class="fa-regular fa-wrench"></i>&nbsp;
            <span class="desktop">2023-06-05 00:41:27</span>
            <span class="mobile">2023-06-05 00:41</span>
            <span class="hover-info">更新</span>
        </span>
    

    
        <span class="article-categories article-meta-item">
            <i class="fa-regular fa-folders"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fa-regular fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/git/">git</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
        <span class="article-pv article-meta-item">
            <i class="fa-regular fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                        </div>
                    </div>
                </div>
            

            <div class="article-content markdown-body">
                <h1 id="git常用命令"><a class="markdownIt-Anchor" href="#git常用命令">#</a> Git 常用命令</h1>
<h2 id="查看版本号"><a class="markdownIt-Anchor" href="#查看版本号">#</a> 查看版本号</h2>
<ul>
<li>git --version</li>
</ul>
<h2 id="清屏"><a class="markdownIt-Anchor" href="#清屏">#</a> 清屏</h2>
<ul>
<li>clear</li>
</ul>
<h2 id="设置签名"><a class="markdownIt-Anchor" href="#设置签名">#</a> 设置签名</h2>
<ul>
<li>git config --global <a class="link"   target="_blank" rel="noopener" href="http://user.name" >user.name <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a> “dujinliang”</li>
</ul>
<h2 id="设置邮箱"><a class="markdownIt-Anchor" href="#设置邮箱">#</a> 设置邮箱</h2>
<ul>
<li>git config --global user.email “<a class="link"   href="mailto:1162378922@qq.com" >1162378922@qq.com <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a>”</li>
</ul>
<h2 id="查看设置"><a class="markdownIt-Anchor" href="#查看设置">#</a> 查看设置</h2>
<ul>
<li>git config --global --list</li>
</ul>
<h2 id="切换目录"><a class="markdownIt-Anchor" href="#切换目录">#</a> 切换目录</h2>
<ul>
<li>cd E:</li>
</ul>
<h2 id="本地仓库的初始化"><a class="markdownIt-Anchor" href="#本地仓库的初始化">#</a> 本地仓库的初始化</h2>
<ul>
<li>git init</li>
</ul>
<h2 id="显示文件夹下的文件"><a class="markdownIt-Anchor" href="#显示文件夹下的文件">#</a> 显示文件夹下的文件</h2>
<ul>
<li>ll</li>
<li>ll -la
<ul>
<li>显示隐藏文件</li>
</ul>
</li>
</ul>
<h2 id="将文件提交到暂存区"><a class="markdownIt-Anchor" href="#将文件提交到暂存区">#</a> 将文件提交到暂存区</h2>
<ul>
<li>git add Demo.txt</li>
</ul>
<h2 id="将暂存区中的内容提交到本地库"><a class="markdownIt-Anchor" href="#将暂存区中的内容提交到本地库">#</a> 将暂存区中的内容提交到本地库</h2>
<ul>
<li>git commit -m “这是我提交的第一个文件” Demo.txt</li>
</ul>
<h2 id="查看工作区和暂存区的状态"><a class="markdownIt-Anchor" href="#查看工作区和暂存区的状态">#</a> 查看工作区和暂存区的状态</h2>
<ul>
<li>git status</li>
</ul>
<h2 id="查看提交的历史记录从近到远"><a class="markdownIt-Anchor" href="#查看提交的历史记录从近到远">#</a> 查看提交的历史记录（从近到远）</h2>
<ul>
<li>git log
<ul>
<li>到日志过多，会出现分页的效果</li>
<li>下一页 ： 空格</li>
<li>上一页 ：b</li>
<li>到页尾，显示 END</li>
<li>退出 ：q</li>
</ul>
</li>
<li>git log --pretty=oneline
<ul>
<li>在一行中进行展示</li>
</ul>
</li>
<li>git log --oneline
<ul>
<li>在一行进行展示，关键字是简写的</li>
</ul>
</li>
<li>git reflog
<ul>
<li>在一行进行展示，关键字是简写的，有一个回退步数的显示，HEAD@{数字}，即回到当前这个历史版本需要走多少步</li>
</ul>
</li>
</ul>
<h2 id="版本回退"><a class="markdownIt-Anchor" href="#版本回退">#</a> 版本回退</h2>
<ul>
<li>git reset --hard 索引号
<ul>
<li>本地库指针移动的同时，重置暂存区，重置工作区</li>
</ul>
</li>
<li>git reset --mixed 索引号
<ul>
<li>本地库的指针移动的同时，重置暂存区，但是工作区不动</li>
</ul>
</li>
<li>git reset --soft
<ul>
<li>本地库指针移动的时候，暂存区和工作区都不动</li>
</ul>
</li>
</ul>
<h2 id="删除文件"><a class="markdownIt-Anchor" href="#删除文件">#</a> 删除文件</h2>
<ul>
<li>删除工作区中的文件
<ul>
<li>tm  Test.txt</li>
</ul>
</li>
<li>将删除操作同步到暂存区
<ul>
<li>git add Test.txt</li>
</ul>
</li>
<li>将删除操作同步到本地库
<ul>
<li>git commit -m “删除 Text.txt 文件” Test.txt</li>
</ul>
</li>
</ul>
<h2 id="找回本地库中删除的文件"><a class="markdownIt-Anchor" href="#找回本地库中删除的文件">#</a> 找回本地库中删除的文件</h2>
<ul>
<li>实际上就是将历史版本切换到刚才添加文件的那个版本即可
<ul>
<li>git reset --hard 索引号</li>
</ul>
</li>
</ul>
<h2 id="找回暂存区中删除的文件"><a class="markdownIt-Anchor" href="#找回暂存区中删除的文件">#</a> 找回暂存区中删除的文件</h2>
<ul>
<li>删除工作区数据
<ul>
<li>rm Test.txt</li>
</ul>
</li>
<li>同步到缓存区
<ul>
<li>git add Test.txt</li>
</ul>
</li>
<li>恢复暂存区中的数据
<ul>
<li>git reset --hard 索引号</li>
<li>git reset --hard HEAD</li>
</ul>
</li>
</ul>
<h2 id="比较文件"><a class="markdownIt-Anchor" href="#比较文件">#</a> 比较文件</h2>
<ul>
<li>
<p>git 是按照行为单位管理数据，所以删除一行，添加一行</p>
</li>
<li>
<p>将工作区中的文件和暂存区中的文件进行比较</p>
<ul>
<li>git diff [文件名]</li>
</ul>
</li>
<li>
<p>多个文件的比对，比较工作区和暂存区中所有的差异</p>
<ul>
<li>git diff</li>
</ul>
</li>
<li>
<p>比较暂存区和工作区中的差别、</p>
<ul>
<li>git diff [历史版本] [文件名]</li>
</ul>
</li>
</ul>
<h2 id="分支"><a class="markdownIt-Anchor" href="#分支">#</a> 分支</h2>
<ul>
<li>同时多个分支可以并发开发，互相不耽误，互相不影响，提高开发效率</li>
<li>如果有一个分支功能开发失败，直接删除这个分支就可以了，不会对其他分支产生任何影响</li>
</ul>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154218643.png"
                      alt="在这里插入图片描述"
                ></p>
<h2 id="查看分支"><a class="markdownIt-Anchor" href="#查看分支">#</a> 查看分支</h2>
<ul>
<li>git branch -v</li>
</ul>
<h2 id="创建分支"><a class="markdownIt-Anchor" href="#创建分支">#</a> 创建分支</h2>
<ul>
<li>git branch branch01</li>
<li>你在哪个分支上，是通过 * 来显示的</li>
<li><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154444325.png"
                      alt="在这里插入图片描述"
                ></li>
</ul>
<h2 id="切换分支"><a class="markdownIt-Anchor" href="#切换分支">#</a> 切换分支</h2>
<ul>
<li>git checkout branch01</li>
<li><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154509695.png"
                      alt="在这里插入图片描述"
                ></li>
</ul>
<h2 id="合并分支"><a class="markdownIt-Anchor" href="#合并分支">#</a> 合并分支</h2>
<ul>
<li>先切换到主方法中</li>
<li>git merge branch01
<ul>
<li><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154531941.png"
                      alt="在这里插入图片描述"
                ></li>
</ul>
</li>
</ul>
<h2 id="查看文件内容"><a class="markdownIt-Anchor" href="#查看文件内容">#</a> 查看文件内容</h2>
<ul>
<li>cat Test5.txt</li>
<li>出现冲突
<ul>
<li>
<p>在用同一个文件的同一个位置修改</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154603510.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>经过商议，留下想要的</p>
</li>
<li>
<p>将工作区中内容添加到暂存区</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154648468.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>然后进行 commit 操作</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154708513.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
</ul>
</li>
</ul>
<h2 id="查看别名"><a class="markdownIt-Anchor" href="#查看别名">#</a> 查看别名</h2>
<ul>
<li>git remote -v</li>
</ul>
<h2 id="创建别名"><a class="markdownIt-Anchor" href="#创建别名">#</a> 创建别名</h2>
<ul>
<li>
<p>git remote add 别名 地址</p>
<ul>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407154739663.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>fetch</p>
<ul>
<li>获取</li>
</ul>
</li>
<li>
<p>push</p>
<ul>
<li>推送</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="向远程库推送数据"><a class="markdownIt-Anchor" href="#向远程库推送数据">#</a> 向远程库推送数据</h2>
<ul>
<li>git push 远程库别名 要推送的分支
<ul>
<li><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407160838761.png"
                      alt="在这里插入图片描述"
                ></li>
</ul>
</li>
</ul>
<h2 id="从远程库克隆数据"><a class="markdownIt-Anchor" href="#从远程库克隆数据">#</a> 从远程库克隆数据</h2>
<ul>
<li>
<p>git clone 远程库的地址</p>
</li>
<li>
<p>克隆操作可以帮我们完成</p>
<ul>
<li>初始化本地库</li>
<li>将远程库内容完整的克隆到本地</li>
<li>替我们创建远程库别名</li>
</ul>
</li>
</ul>
<h2 id="加入团队"><a class="markdownIt-Anchor" href="#加入团队">#</a> 加入团队</h2>
<ul>
<li>可以从 GitHub 中 clone 对方的数据，但无法提交，可由对方向自己发送邀请，复制邀请链接，由被邀请者在浏览器中打开同意即可</li>
</ul>
<h2 id="拉取操作"><a class="markdownIt-Anchor" href="#拉取操作">#</a> 拉取操作</h2>
<ul>
<li>pull 操作，相当于 fetch + merge</li>
</ul>
<h2 id="抓取操作"><a class="markdownIt-Anchor" href="#抓取操作">#</a> 抓取操作</h2>
<ul>
<li>
<p>git fetch origin master</p>
</li>
<li>
<p>在抓取操作执行后，只是将远程库的内容下载到本地，但是工作区中的文件并没有更新，工作区中还是原先的内容</p>
</li>
<li>
<p>抓取后可以去远程库看看内容是否正确</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407160902432.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>发现内容都正确，就可以进行合并操作了</p>
<ul>
<li>
<p>合并之前应该将分支切换回来</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407160924479.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>进行合并：merge</p>
</li>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407160942142.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
</ul>
</li>
<li>
<p>远程库的拉取可以直接利用 pull 命令来完成</p>
<ul>
<li>git pull origin master</li>
</ul>
</li>
</ul>
<p><strong>区别</strong></p>
<ul>
<li>
<p>fetch  + merge 操作</p>
<ul>
<li>为了保险，慎重</li>
</ul>
</li>
<li>
<p>pull</p>
<ul>
<li>代码简单，省事</li>
</ul>
</li>
<li>
<p>多人共同提交数据时，会出现冲突问题，当一个人提交完成后，另一个人提交时会报错，需要先抓取该数据，对冲突进行处理，再提交，再提交时，git commit “注释信息”, 此处不写文件名</p>
</li>
</ul>
<h2 id="跨团队合作"><a class="markdownIt-Anchor" href="#跨团队合作">#</a> 跨团队合作</h2>
<ul>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://img-blog.csdnimg.cn/2021040716101181.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BlbmFudXQ=,size_16,color_FFFFFF,t_70#pic_center"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>获取远程库地址</p>
</li>
<li>
<p>进行 fork 操作</p>
<ul>
<li>进入账号后，复制地址</li>
<li>点击 fork 操作</li>
<li><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407161030420.png"
                      alt="在这里插入图片描述"
                ></li>
</ul>
</li>
<li>
<p>克隆操作</p>
</li>
<li>
<p>然后更改数据，添加到暂存区，然后提交到本地库，然后 push 到远程库</p>
</li>
<li>
<p>进行 pull request，等待审核</p>
</li>
<li>
<p>进行审核</p>
</li>
<li>
<p>可以互相留言</p>
</li>
<li>
<p>确定通过后，merge 合并</p>
</li>
</ul>
<h2 id="免密操作"><a class="markdownIt-Anchor" href="#免密操作">#</a> 免密操作</h2>
<ul>
<li>
<p>进入用户主目录中，</p>
<ul>
<li>cd ~</li>
</ul>
</li>
<li>
<p>执行命令，生成一个.ssh 目录</p>
<ul>
<li>ssh-keygen -t rsa -C GitHub 邮箱</li>
<li>C 要大写，邮箱是 GitHub 注册的账号的时候对应的邮箱</li>
<li>三次回车确认默认值即可</li>
</ul>
</li>
<li>
<p>发现在.ssh 目录下有两个文件</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407161051391.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>打开 id_rad.pub 文件，将里面的内容进行复制操作</p>
</li>
<li>
<p>打开 GitHub 账号，找到 settings，ssh and gpg keys，new ssh keys</p>
<ul>
<li>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/20210407161122503.png"
                      alt="在这里插入图片描述"
                ></p>
</li>
<li>
<p>生成密钥以后，就可以正常进行 push 操作了</p>
<ul>
<li>对 ssh 远程地址起别名</li>
<li>展示别名</li>
<li>添加到暂存区，提交到本地库，然后 push 到远程库（地址用的是 ssh 方式的地址）</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="允许不相关历史的合并"><a class="markdownIt-Anchor" href="#允许不相关历史的合并">#</a> 允许不相关历史的合并</h2>
<ul>
<li>
<p>用于两个仓库有不同的开始点</p>
</li>
<li>
<p>–allow -unrelated-histories</p>
</li>
<li>
<p>git pull 地址 master --allow -unrelated-histories</p>
<ul>
<li>i 进入编辑</li>
<li>ese 退出编辑，：wq 退出</li>
</ul>
</li>
<li>
<p>push 推送</p>
<ul>
<li>git push -u origin master -f</li>
</ul>
</li>
<li>
<p>这样远程库和本地库就可以交互了</p>
</li>
<li>
<p>一般在开发中，先 pull 操作，再 push 操作，不会直接进行 push 操作</p>
</li>
</ul>

            </div>

            
                <div class="post-copyright-info">
                    <div class="article-copyright-info-container">
    <ul>
        <li><strong>标题:</strong> Git常用命令</li>
        <li><strong>作者:</strong> meteor</li>
        <li><strong>创建于:</strong> 2023-06-05 16:41:10</li>
        
            <li>
                <strong>更新于:</strong> 2023-06-05 00:41:27
            </li>
        
        <li>
            <strong>链接:</strong> https://gitee.com/du-jinliang/2023/06/06/Git常用命令/
        </li>
        <li>
            <strong>版权声明:</strong> 本文章采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0</a> 进行许可。
        </li>
    </ul>
</div>

                </div>
            

            
                <ul class="post-tags-box">
                    
                        <li class="tag-item">
                            <a href="/tags/git/">#git</a>&nbsp;
                        </li>
                    
                </ul>
            

            

            
                <div class="article-nav">
                    
                        <div class="article-prev">
                            <a class="prev"
                            rel="prev"
                            href="/2023/06/06/JAVA%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/"
                            >
                                <span class="left arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-left"></i>
                                </span>
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">JAVA并发编程</span>
                                    <span class="post-nav-item">上一篇</span>
                                </span>
                            </a>
                        </div>
                    
                    
                        <div class="article-next">
                            <a class="next"
                            rel="next"
                            href="/2023/06/06/ECMAScript6/"
                            >
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">ECMAScript6</span>
                                    <span class="post-nav-item">下一篇</span>
                                </span>
                                <span class="right arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-right"></i>
                                </span>
                            </a>
                        </div>
                    
                </div>
            


            
                <div class="comment-container">
                    <div class="comments-container">
    <div id="comment-anchor"></div>
    <div class="comment-area-title">
        <i class="fa-solid fa-comments"></i>&nbsp;评论
    </div>
    

        
            
    <div id="gitalk-container"></div>
    <script data-pjax
            src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
    <script data-pjax>

        function loadGitalk() {
            let __gitalk__pathname = decodeURI(location.pathname);
            const __gitalk__pathnameLength = __gitalk__pathname.length;
            const __gitalk__pathnameMaxLength = 50;
            if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) {
                __gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...';
            }

            try {
                Gitalk && new Gitalk({
                    clientID: '55bad54a77b7e60ad62d',
                    clientSecret: '1031c81500c6be06e338087cb7b713f2d0201b46',
                    repo: 'wait-you.github.io',
                    owner: 'wait-you',
                    admin: ['wait-you'],
                    id: 'comment',
                    language: 'zh-CN'
                }).render('gitalk-container');

            } catch (e) {
                window.Gitalk = null;
            }
        }

        if ('true') {
            const loadGitalkTimeout = setTimeout(() => {
                loadGitalk();
                clearTimeout(loadGitalkTimeout);
            }, 1000);
        } else {
            window.addEventListener('DOMContentLoaded', loadGitalk);
        }
    </script>



        
    
</div>

                </div>
            
        </div>

        
            <div class="toc-content-container">
                <div class="post-toc-wrap">
    <div class="post-toc">
        <div class="toc-title">此页目录</div>
        <div class="page-title">Git常用命令</div>
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-text"> Git 常用命令</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%89%88%E6%9C%AC%E5%8F%B7"><span class="nav-text"> 查看版本号</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B8%85%E5%B1%8F"><span class="nav-text"> 清屏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E7%AD%BE%E5%90%8D"><span class="nav-text"> 设置签名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E9%82%AE%E7%AE%B1"><span class="nav-text"> 设置邮箱</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E8%AE%BE%E7%BD%AE"><span class="nav-text"> 查看设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%87%E6%8D%A2%E7%9B%AE%E5%BD%95"><span class="nav-text"> 切换目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text"> 本地仓库的初始化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%98%BE%E7%A4%BA%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E7%9A%84%E6%96%87%E4%BB%B6"><span class="nav-text"> 显示文件夹下的文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B0%86%E6%96%87%E4%BB%B6%E6%8F%90%E4%BA%A4%E5%88%B0%E6%9A%82%E5%AD%98%E5%8C%BA"><span class="nav-text"> 将文件提交到暂存区</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B0%86%E6%9A%82%E5%AD%98%E5%8C%BA%E4%B8%AD%E7%9A%84%E5%86%85%E5%AE%B9%E6%8F%90%E4%BA%A4%E5%88%B0%E6%9C%AC%E5%9C%B0%E5%BA%93"><span class="nav-text"> 将暂存区中的内容提交到本地库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%B7%A5%E4%BD%9C%E5%8C%BA%E5%92%8C%E6%9A%82%E5%AD%98%E5%8C%BA%E7%9A%84%E7%8A%B6%E6%80%81"><span class="nav-text"> 查看工作区和暂存区的状态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E7%9A%84%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95%E4%BB%8E%E8%BF%91%E5%88%B0%E8%BF%9C"><span class="nav-text"> 查看提交的历史记录（从近到远）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%89%88%E6%9C%AC%E5%9B%9E%E9%80%80"><span class="nav-text"> 版本回退</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6"><span class="nav-text"> 删除文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%BE%E5%9B%9E%E6%9C%AC%E5%9C%B0%E5%BA%93%E4%B8%AD%E5%88%A0%E9%99%A4%E7%9A%84%E6%96%87%E4%BB%B6"><span class="nav-text"> 找回本地库中删除的文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%BE%E5%9B%9E%E6%9A%82%E5%AD%98%E5%8C%BA%E4%B8%AD%E5%88%A0%E9%99%A4%E7%9A%84%E6%96%87%E4%BB%B6"><span class="nav-text"> 找回暂存区中删除的文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%AF%94%E8%BE%83%E6%96%87%E4%BB%B6"><span class="nav-text"> 比较文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%86%E6%94%AF"><span class="nav-text"> 分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%88%86%E6%94%AF"><span class="nav-text"> 查看分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF"><span class="nav-text"> 创建分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF"><span class="nav-text"> 切换分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%88%E5%B9%B6%E5%88%86%E6%94%AF"><span class="nav-text"> 合并分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9"><span class="nav-text"> 查看文件内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%88%AB%E5%90%8D"><span class="nav-text"> 查看别名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%88%AB%E5%90%8D"><span class="nav-text"> 创建别名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%91%E8%BF%9C%E7%A8%8B%E5%BA%93%E6%8E%A8%E9%80%81%E6%95%B0%E6%8D%AE"><span class="nav-text"> 向远程库推送数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%8E%E8%BF%9C%E7%A8%8B%E5%BA%93%E5%85%8B%E9%9A%86%E6%95%B0%E6%8D%AE"><span class="nav-text"> 从远程库克隆数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A0%E5%85%A5%E5%9B%A2%E9%98%9F"><span class="nav-text"> 加入团队</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8B%89%E5%8F%96%E6%93%8D%E4%BD%9C"><span class="nav-text"> 拉取操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8A%93%E5%8F%96%E6%93%8D%E4%BD%9C"><span class="nav-text"> 抓取操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%B7%A8%E5%9B%A2%E9%98%9F%E5%90%88%E4%BD%9C"><span class="nav-text"> 跨团队合作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%8D%E5%AF%86%E6%93%8D%E4%BD%9C"><span class="nav-text"> 免密操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%81%E8%AE%B8%E4%B8%8D%E7%9B%B8%E5%85%B3%E5%8E%86%E5%8F%B2%E7%9A%84%E5%90%88%E5%B9%B6"><span class="nav-text"> 允许不相关历史的合并</span></a></li></ol></li></ol>

    </div>
</div>
            </div>
        
    </div>
</div>


                

            </div>
            
            

        </div>

        <div class="main-content-footer">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info">
            &copy;
            
              <span>2022</span>
              -
            
            2023&nbsp;&nbsp;<i class="fa-solid fa-heart fa-beat" style="--fa-animation-duration: 0.5s; color: #f54545"></i>&nbsp;&nbsp;<a href="/">meteor</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv" class="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv" class="busuanzi_value_site_uv"></span>
                    </span>
                
                
                    <span id="busuanzi_container_site_pv" class="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv" class="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="theme-info info-item">
            <span class="powered-by-container">由 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1rem" height="1rem" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve"><path fill="#0E83CD" d="M256.4,25.8l-200,115.5L56,371.5l199.6,114.7l200-115.5l0.4-230.2L256.4,25.8z M349,354.6l-18.4,10.7l-18.6-11V275H200v79.6l-18.4,10.7l-18.6-11v-197l18.5-10.6l18.5,10.8V237h112v-79.6l18.5-10.6l18.5,10.8V354.6z"/></svg><a target="_blank" href="https://hexo.io">Hexo</a> 驱动</span>
                <br>
            <span class="theme-version-container">主题&nbsp;<a class="theme-version" target="_blank" href="https://github.com/EvanNotFound/hexo-theme-redefine">Redefine v2.1.4</a>
        </div>
        
            <div class="icp-info info-item"><a target="_blank" rel="nofollow" href="
                
                    beian.miit.gov.cn
                
                ">冀ICP备20010108号</a></div>
        
        
        
            <div id="start_div" style="display:none">
                2022/8/17 11:45:14
            </div>
            <div>
                博客已运行 <span class="odometer" id="runtime_days" ></span> 天 <span class="odometer" id="runtime_hours"></span> 小时 <span class="odometer" id="runtime_minutes"></span> 分钟 <span class="odometer" id="runtime_seconds"></span> 秒
            </div>
        
        
        
            <script async data-pjax>
                try {
                    function odometer_init() {
                    const elements = document.querySelectorAll('.odometer');
                    elements.forEach(el => {
                        new Odometer({
                            el,
                            format: '( ddd).dd',
                            duration: 200
                        });
                    });
                    }
                    odometer_init();
                } catch (error) {}
            </script>
        
        
        
    </div>  
</footer>
        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="article-tools-list">
        <!-- TOC aside toggle -->
        
            <li class="right-bottom-tools page-aside-toggle">
                <i class="fa-regular fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
            <li class="go-comment">
                <i class="fa-regular fa-comments"></i>
            </li>
        
    </ul>
</div>

        </div>
    

    <div class="right-side-tools-container">
        <div class="side-tools-container">
    <ul class="hidden-tools-list">
        <li class="right-bottom-tools tool-font-adjust-plus flex-center">
            <i class="fa-regular fa-magnifying-glass-plus"></i>
        </li>

        <li class="right-bottom-tools tool-font-adjust-minus flex-center">
            <i class="fa-regular fa-magnifying-glass-minus"></i>
        </li>

        <li class="right-bottom-tools tool-expand-width flex-center">
            <i class="fa-regular fa-expand"></i>
        </li>

        <li class="right-bottom-tools tool-dark-light-toggle flex-center">
            <i class="fa-regular fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="right-bottom-tools tool-scroll-to-bottom flex-center">
            <i class="fa-regular fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="visible-tools-list">
        <li class="right-bottom-tools toggle-tools-list flex-center">
            <i class="fa-regular fa-cog fa-spin"></i>
        </li>
        
            <li class="right-bottom-tools tool-scroll-to-top flex-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
        
    </ul>
</div>

    </div>

    <div class="image-viewer-container">
    <img src="">
</div>


    


</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/layouts/navbarShrink.js"></script>

<script src="/js/tools/scrollTopBottom.js"></script>

<script src="/js/tools/lightDarkSwitch.js"></script>





    
<script src="/js/tools/codeBlock.js"></script>




    
<script src="/js/layouts/lazyload.js"></script>




    
<script src="/js/tools/runtime.js"></script>

    
<script src="/js/layouts/odometer.min.js"></script>

    
<link rel="stylesheet" href="/assets/odometer-theme-minimal.css">




  
<script src="/js/libs/Typed.min.js"></script>

  
<script src="/js/plugins/typed.js"></script>







<div class="post-scripts pjax">
    
        
<script src="/js/tools/tocToggle.js"></script>

<script src="/js/libs/anime.min.js"></script>

<script src="/js/layouts/toc.js"></script>

<script src="/js/plugins/tabs.js"></script>

    
</div>


    
<script src="/js/libs/pjax.min.js"></script>

<script>
    window.addEventListener('DOMContentLoaded', () => {
        window.pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax',
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            Global.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            Global.utils.pjaxProgressBarEnd();
            window.pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            Global.refresh();
        });
    });
</script>




</body>
</html>
